package com.hkrt.demo.demo1.service;

import com.hkrt.demo.demo1.dao.Dao;
import com.hkrt.demo.demo1.entity.User;

import java.util.List;

/**
 * Created by admin on 2019/12/4.
 */
public class Service {
    private Dao dao = new Dao();

    public String insert(User user){
        int rows = dao.insert(user);
        if (rows==0){
            return "添加失败";
        }else if (rows==1){
            return "添加成功";
        }
        return "异常";
    }

    public String delect(User user){
        int rows = dao.delete(user);
        if (rows==0){
            return "删除失败";
        }else if (rows==1){
            return "删除成功";
        }
        return "异常";
    }

    public String update(User user){
        int rows = dao.update(user);
        if (rows==0){
            return "修改失败";
        }else if (rows==1){
            return "修改成功";
        }
        return "异常";
    }

    public User query(User user){
        List<User> userList = dao.select(user);
        if (!userList.isEmpty()&&userList!=null){
            user = userList.get(0);
        }
        return user;
    }

}
